package com.objectdraw.client.objectdraw;
//import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.objectdraw.client.*;
//import java.util.EventListener;


/**
 * creates a listener for a tool
 */
@SuppressWarnings("serial")
public class ToolListener extends AbstractAction {

	protected DrawingCanvas canvas;
	protected Tool tool;
	protected clientcomm com;

	/**
	 * 
	 * @param name name of the tool
	 * @param icon icon for the tool
	 * @param tip tool tip
	 * @param canvas the canvas to which the listeners listens
	 * @param tool the tool the listener is attached to
	 * @param com the communication channel from which this listener will send messages
	 */
	public ToolListener(String name, Icon icon, String tip,
			DrawingCanvas canvas, Tool tool, clientcomm com) {
		super(name);
		putValue(Action.SMALL_ICON, icon);
		putValue(Action.SHORT_DESCRIPTION, tip);
		setEnabled(tool != null);
		this.canvas = canvas; 
		this.tool = tool;
		this.com=com;
	} 

	/**
	 * sets the cavas' tool to whatever is in the provided event
	 */
	public void actionPerformed(ActionEvent e) {
		if(canvas.control){
			if(com!=null){com.sendMessage("tool "+super.getValue(Action.NAME));}
			canvas.setCurrentTool(tool);
		}
	}

}
